/*
 * forecastCourseDetail js
 */

var forecastCourseLiList = [];
var forecastCourseContentList = [];
var forecastCourseLiListStr = "offCRaddressLi,courseContentOutlineLi,teacherIntroductionLi"; 
var forecastCourseContentListStr = "offCRaddress,courseContentOutline,teacherIntroduction";


$(document).ready(function(){
	/*
	 * init the google map
	 */
	initGoogleMap();
	
	forecastCourseLiList = forecastCourseLiListStr.split(",");
	forecastCourseContentList = forecastCourseContentListStr.split(",");
	
	/*
	 * for auto slide of images
	 */
	var speed = 3000;
	var gallery = document.getElementById("outerImgGallery");
	
	function autoRun(){
		nextImg("outerImgGallery", "insideImgGallery");
	}

	var autoRunMethod = setInterval(autoRun, speed);
	gallery.onmouseover = function() {clearInterval(autoRunMethod)};
	gallery.onmouseout = function() {autoRunMethod = setInterval(autoRun, speed)};
})

/*
 * google map
 */
var geocoder;    
var map;    
 
function initGoogleMap() {    
    geocoder = new google.maps.Geocoder();    
    var myOptions = {    
        zoom : 17,
        mapTypeId : google.maps.MapTypeId.ROADMAP    
    }    
    map = new google.maps.Map(document.getElementById("classroom_map"),    
            myOptions);    
    getLocationFromAddress();    
}    
function getLocationFromAddress() { 
	
	var address = document.getElementById("classroom_address").value;
	
	var address = (null == address) ? "上海，徐汇区，桂林路， 上海师范大学" : address;
    
    geocoder.geocode({    
        'address' : address    
    }, function(results, status) {    
        if (status == google.maps.GeocoderStatus.OK) {    
            map.setCenter(results[0].geometry.location);    
            var marker = new google.maps.Marker({    
                map : map,    
                position : results[0].geometry.location,    
                title : address,    
                animation : google.maps.Animation.DROP    
            });    
//            var display = "地址: " + results[0].formatted_address;  
//            var infowindow = new google.maps.InfoWindow({    
//                content : "<span style='font-size:12px'><b>名称: </b>"    
//                        + address + "<br>" + display + "</span>", 
//                
//                        pixelOffset : 0,    
//                position : results[0].geometry.location    
//            });  
//            
//            infowindow.open(map, marker);    
//            google.maps.event.addListener(marker, 'click', function() {    
//                infowindow.open(map, marker);    
//            });   
            
        } else {    
        	//Todo
        	alert("Geocode was not successful for the following reason: " + status); 
        }    
    });    
}    

/*
 * change to relative content
 */
function showFCDRelativeContent(forecastCourseLi, forecastCourseContent){
	var i=0;
	for(i; i<forecastCourseLiList.length; i++){
		$("#" + forecastCourseLiList[i]).removeClass("active");
		$("#" + forecastCourseContentList[i]).addClass("hide");
	}
	$("#" + forecastCourseLi).addClass("active");
	$("#" + forecastCourseContent).removeClass("hide");
}


/*
 * images slide
 */
function previousImg(gallery, galleryInside){
	
	var mediaGallery = document.getElementById(gallery);
	var width = document.getElementById(galleryInside).style.width;
	
	if(mediaGallery.scrollLeft == 0){
		mediaGallery.scrollLeft = parseInt(width) - 558;
	}else{
		mediaGallery.scrollLeft = mediaGallery.scrollLeft - 558;
	}
	
}

function nextImg(gallery, galleryInside){
	
	var mediaGallery = document.getElementById(gallery);
	var width = document.getElementById(galleryInside).style.width;
	
	if(mediaGallery.scrollLeft == (parseInt(width) - 558)){
		mediaGallery.scrollLeft = 0;
	}else{
		mediaGallery.scrollLeft = mediaGallery.scrollLeft + 558;
	}
}



